package com.zoe.onelink.guide.autoconfigure;

import com.zoe.onelink.core.exception.guide.OnelinkExceptionGuideProvider;
import com.zoe.onelink.guide.loader.OnelinkGuideLoader;
import com.zoe.onelink.guide.loader.impl.OnelinkApiExceptionGuideLoader;
import com.zoe.onelink.guide.property.OnelinkGuideProperties;
import com.zoe.onelink.guide.provider.OnelinkApiExceptionGuideProvider;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Map;

/**
 * <p>标题: </p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2022</p>
 * <p>公司: 智业软件股份有限公司</p>
 *
 * @version: 1.0
 * @author: ruansheng
 * @date: 2022-11-21
 */
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(OnelinkExceptionGuideProvider.class)
@EnableConfigurationProperties(OnelinkGuideProperties.class)
public class OnelinkGuideAutoConfiguration {

    @Bean
    public OnelinkApiExceptionGuideLoader onelinkApiExceptionGuideLoader() {
        return new OnelinkApiExceptionGuideLoader();
    }

    @Bean
    @ConditionalOnProperty(prefix = OnelinkGuideProperties.PREFIX, name = "enabled")
    public OnelinkExceptionGuideProvider onelinkApiExceptionGuideProvider(ObjectProvider<Map<String, OnelinkGuideLoader>> onelinkGuideLoaderMap) {
        return new OnelinkApiExceptionGuideProvider(onelinkGuideLoaderMap.getIfAvailable());
    }

}
